var host = "http://localhost:80/";
//        contentType: "application/json;charset=UTF-8",
function send(url,param,callback) {
    $.ajax({
        method:"POST",
        url:host+url,
        data:param,
        dataType:"JSON",
        success:function (resp) {
            callback(resp);
        }
    })
}

function get(url,callback) {
    $.ajax({
        method: "GET",
        url: host+url,
        dataType: "JSON",
        success:function (resp) {
            callback(resp);
        }
    })
}

/*
* 表单序列化,返回封装好的对象
* */
function formToObject(from) {
    //1.表单序列化
    var fromArray = from.serializeArray();
    //2.将表单数据封装
    var param = new Object();

    for (var i = 0; i < fromArray.length; i++) {
        //获取表单name属性值
        var inputName = fromArray[i].name;
        //获取表单属性对应的值
        var inputValue = fromArray[i].value;
        //赋值
        param[inputName] = inputValue;
    }
    return param;
}

/*
* 表单提交
* */
function submit(from,url) {
    //序列化表单数据并封装
    var param = formToObject(from);
    //异步请求
    $.post(host+url,param,function (data) {
        //1.判断请求是否处理成功
        if (data.status=="success"){
            layer.msg("操作成功",{icon:1,time: 1000},function () {
                // 关闭提示层
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });
        }else {
            layer.msg(data.msg,{icon: 2,time: 1000});
        }
    },"JSON");
}